Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
A collection of useful CoffeeScript/JavaScript functions.
Destructively remove an element from an array. Returns the element removed.
a = w "foo bar baz"
remove( a, "bar" )
Takes an array and returns a new array with all duplicate values from the original array removed. Also takes an optional hash function that defaults to calling toString
on the elements.
uniq [1,2,3,1,2,3,4,5,6,3,6,2,4]
# returns [1,2,3,4,5,6]
Takes an array and returns a new array with all values shuffled randomly.
shuffle ["a", "b", "c", "d", "e", "f"]
# for e.g.: returns ["b", "c", "d", "e", "f", "a"]
Use the Fisher-Yates algorithm.
Adapted from the CoffeeScript Cookbook.
Return the MD5 hash of a string.
nutshell = md5( myLifeStory )
Base64 encode a string. (Not URL safe.)
image = data: base64( imageData )
All file-system functions are based on Node's fs
API. This is not require
d unless the function is actually invoked.
Check to see if a file exists.
source = read( sourcePath ) if exists( sourcePath )
Read a file synchronously and return a UTF-8 string of the contents.
source = read( sourcePath ) if exists( sourcePath )
Synchronously get the contents of a directory as an array.
for file in readdir("documents")
console.log read( file ) if stat( file ).isFile()
Synchronously get the stat object for a file.
for file in readdir("documents")
console.log read( file ) if stat( file ).isFile()
Synchronously write a UTF-8 string to a file.
write( file.replace( /foo/g, 'bar' ) )
Change directories, execute a function, and then restore the original working directory.
chdir "documents", ->
console.log read( "README" )
Removes a file.
rm "documents/reamde.txt"
Removes a directory.
rmdir "documents"
Split a string on whitespace. Useful for concisely creating arrays of strings.
console.log word for word in w "foo bar baz"
Hoist a value to a given type if it isn't already. Useful when you want to wrap a value without having to check to see if it's already wrapped.
For example, to hoist an error message into an error, you would use:
to(error, Error)
Simple wrapper around process.exit(-1)
.
A very simple way to cache results of functions that take a single argument. Also takes an optional hash function that defaults to calling toString
on the function's argument.
nickname = (email) ->
expensiveLookupToGetNickname( email )
#
memoize( nickname )
Set a timer. Takes an interval in microseconds and an action. Returns a function to cancel the timer. Basically, a more convenient way to call setTimeout
and clearTimeout
.
cancel = timer 1000, -> console.log "Done"
cancel()
Adds the properties of one or more objects to another.
include( @, ScrollbarMixin, SidebarMixin )
Add a property
method to a class, making it easier to define getters and setters on its prototype.
class Foo
include @, Property
property "foo", get: -> @_foo, set: (v) -> @_foo = v
Properties defined using property
are enumerable.
Delegates from one object to another by creating functions in the first object that call the second.
delegate( aProxy, aServer )
Creates new object by progressively adding the properties of each given object.
options = merge( defaults, globalOptions, localOptions )
Perform a deep clone on an object. Taken from The CoffeeScript Cookboox.
copy = clone original
Capitalize the first letter of a string.
Capitalize the first letter of each word in a string.
Convert a sequence of words into a camel-cased string.
# yields fooBarBaz
camel_case "foo bar baz"
Convert a sequence of words into an underscore-separated string.
# yields foo_bar_baz
underscored "foo bar baz"
Convert a sequence of words into a dash-separated string.
# yields foo-bar-baz
dashed "foo bar baz"
Convert an camel-case or underscore- or dash-separated string into a whitespace separated string.
# all of the following yield foo bar baz
plain_text "fooBarBaz"
plain_text "foo-bar-baz"
plain_text "foo_bar_baz"
Escape a string so that it can be embedded into HTML. Adapted from Mustache.js.
Get the type of a value. Possible values are: number
, string
, 'boolean
, data
, regexp
, function
, array
, object
, null
, undefined
. Adapted from [The CoffeeScript Cookbook][type-0] and based on Douglas Crockford's [remedial JavaScript blog post][type-1].
[type-0]:http://coffeescriptcookbook.com/chapters/classes_and_objects/type-function
[type-1]:http://javascript.crockford.com/remedial.html
foo() if type( foo ) == "function"
FAQs
Functional reactive programming for JavaScript and CoffeeScript.
The npm package fairmont receives a total of 711 weekly downloads. As such, fairmont popularity was classified as not popular.
We found that fairmont demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.